package index

import (
	"github.com/gogf/gf/frame/g"
	"github.com/gogf/gf/net/ghttp"
	"github.com/gogf/gf/os/glog"
	"github.com/gogf/gf/util/guid"
	"websocket/app/service/websocket/privater"
	"websocket/library/response"
)

func Index(r *ghttp.Request) {
	//r.Response.Writeln("go-gf websocket demo")
	glog.Println(privater.WebsocketManager.Keys())
	response.Json(r, 0, "请求成功", privater.WebsocketManager.Keys())
}

func Offline(r *ghttp.Request) {
	client := privater.WebsocketManager.Get(r.Get("unique")).(*privater.Connection)
	client.Close()
	response.Json(r, 0, "请求成功", privater.WebsocketManager.Keys())
}

func Websocket(r *ghttp.Request) {
	r.Response.WriteTpl("ws.html", g.Map{"token": guid.S()})
}
